package cn.iocoder.yudao.module.system.dal.mysql.partnercouponshare;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.partnercouponshare.PartnerCouponShareDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.partnercouponshare.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 合伙人优惠券分享记录 Mapper
 *
 * @author 万民匠心
 */
@Mapper
public interface PartnerCouponShareMapper extends BaseMapperX<PartnerCouponShareDO> {

    default PageResult<PartnerCouponShareDO> selectPage(PartnerCouponSharePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PartnerCouponShareDO>()
                .eqIfPresent(PartnerCouponShareDO::getPartnerCouponId, reqVO.getPartnerCouponId())
                .eqIfPresent(PartnerCouponShareDO::getPartnerId, reqVO.getPartnerId())
                .eqIfPresent(PartnerCouponShareDO::getTemplateId, reqVO.getTemplateId())
                .likeIfPresent(PartnerCouponShareDO::getName, reqVO.getName())
                .eqIfPresent(PartnerCouponShareDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(PartnerCouponShareDO::getStartTime, reqVO.getStartTime())
                .betweenIfPresent(PartnerCouponShareDO::getEndTime, reqVO.getEndTime())
                .betweenIfPresent(PartnerCouponShareDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(PartnerCouponShareDO::getStoreId, reqVO.getStoreId())
                .orderByDesc(PartnerCouponShareDO::getId));
    }

    @Select("SELECT count(0) from system_partner_coupon_share where partner_coupon_id = #{id} and creator = #{userId}")
    Integer selectHasSendCount(@Param("id") Long id, @Param("userId") Long userId);

}